package orbito.util;

import orbito.physics.PhysicsConstants;

public class SimUtils {
	
	/**
	 * Linear interpolation between two numbers.
	 * 
	 * @param a
	 * @param b
	 * @param factor The interpolation factor, typically in [0-1].
	 * @return The interpolated value, rounded to the closest integer.
	 */
	public static int lerp(int a, int b, double factor) {
		return (int) Math.round(a + (b - a) * factor);
	}
	
	/**
	 * Linear interpolation between two numbers.
	 * 
	 * @param a
	 * @param b
	 * @param factor The interpolation factor, typically in [0-1].
	 * @return The interpolated value.
	 */
	public static double lerp(double a, double b, double factor) {
		return a + (b - a) * factor;
	}
	
	/**
	 * Returns the Lorentz factor given the relative velocity rv of two bodies.
	 * 
	 * @param rv The relative velocity of two bodies.
	 * @return The Lorentz factor.
	 */
	public static double lorentzFactor(double rv) {
		return 1 / Math.sqrt(1 - rv * rv / PhysicsConstants.SPEED_OF_LIGHT_SQUARED);
	}
}
